<template>
	<view>
		<view class="activityContent">
			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
				<activity-item v-for="(item, index) in activityList" :key="item.activityId" :activityInfo="item"
					@goActivityDetail="configTemplateView"></activity-item>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import activityItem from '@/pages/activity/components/activity-item.vue'
	import settings from '@/settings.js'
	import {
		apiActivityListArea
	} from '@/api/activity-api.js'
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			activityItem
		},
		data() {
			return {
				activityList: []
			}
		},
		onLoad() {

		},
		methods: {
			// 获取活动列表
			upCallback(page) {
				apiActivityListArea({
					tenantId: this.$store.state.user.tenantId,
					pageNo : page.num,
					pageSize: page.size,
				}).then(res => {
					this.mescroll.endSuccess(res.data.length);
					//设置列表数据
					if (page.num == 1) this.activityList = []; //如果是第一页需手动制空列表
					this.activityList = this.activityList.concat(res.data); //追加新数据
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			// 配置活动模板
			configTemplateView(activityItem) {
				let templateCode = activityItem.templateCode;
				switch (templateCode) {
					case 'YHQ-001': //优惠券模板
						uni.navigateTo({
							url: '/pagesB/activity/template/coupon?activityId=' + activityItem.activityId
						})
						break;
					case 'CX-001': //车型模板
						uni.navigateTo({ 
							url: '/pagesB/activity/template/car?activityId=' + activityItem.activityId
						})
						break;
					case 'ZQ-CX-001': //中秋节车型模板
						uni.navigateTo({
							url: '/pagesB/activity/template/zhongqiu-car?activityId=' + activityItem.activityId
						})
						break;
					case 'ZQ-SQ-001': //中秋节优惠券模板
						uni.navigateTo({
							url: '/pagesB/activity/template/zhongqiu-coupon?activityId=' + activityItem.activityId
						})
						break;
					default:
						break;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.activityContent {
		margin: 20rpx 34rpx;
	}
</style>
